package face.pay.task.terminal.service.impl;

import face.pay.dao.TerminalTargetAllCountDao;
import face.pay.task.terminal.service.ITerminalTargetAllCountRelationService;
import face.pay.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @Classname TerminalTargetOnCountServiceImpl
 * @Description JJL
 * @Date 2019/10/24 13:51
 */
@Service
@Slf4j
public class TerminalTargetAllCountRelationServiceImpl implements ITerminalTargetAllCountRelationService {

    @Autowired
    private TerminalTargetAllCountDao targetAllCountDao;


    /**
     * 添加到 terminal_target_on_count表中
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void terminalTargetAllCountTask() throws Exception {

        log.info("更新设备统计数据");

        String dataDay = DateUtil.dateFormat(new Date(),"yyyy-MM-dd");

        log.info("获取上次数据更新时间");

        String lastRuntime = this.targetAllCountDao.lastRunTime();

        log.info("获取上次数据更新时间"+lastRuntime);

        if(dataDay.equals(lastRuntime)){
            log.info("当日数据已经更新");
            return;
        }
        log.info("当日没有更新 立即更新");
        log.info("清除历史数据");
        targetAllCountDao.truncateTargetAllTable();
        Thread.sleep(1000);
        log.info("更新最新数据");
        targetAllCountDao.updateTargetAllCount();
        log.info("更新完毕");

    }
}
